package org.bridgen.runtime.model;

import org.bridgen.runtime.util.Interval;

/**
 * 
 * @author Emma Söderberg <emma add cs.lth.se>
 *
 */

public class Water extends LexicalNode {
	
	public Water(LexicalNode previous, Interval interval, String value) {
		super(previous, interval, value);
	}
	/*
	public String toString() {
		return "Water\t" + super.toString();
	}
	*/
	public LexicalNode clone(LexicalNode previous) {
		return new Water(previous, getInterval(), getValue());
	}
	public void mergeWith(Water node) {
		if (node == getNext()) {
			this.value += node.value;
			this.interval.mergeWith(node.interval);
			this.setNext(node.getNext());
			LexicalNode next = getNext(); 
			// Next can be null at the end of a list
			if (next != null) {
				next.setPrevious(this);
			}
		} else {
			throw new Error("Can only merge to consecutive Water nodes");
		}
	}
}
